#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
char mp[35][35][35];
int l,r,c;
typedef struct Node{
    int x,y,z;
    int step;
}node;
int s_x,s_y,s_z;
int e_x,e_y,e_z;
int flag;
int mv[6][3] = {{0,0,1},{0,0,-1},{1,0,0},{-1,0,0},{0,1,0},{0,-1,0}};
int vis[35][35][35];

void bfs(int x,int y,int z){
    queue<node> q;
    node start;
    start.x = s_x;
    start.y = s_y;
    start.z = s_z;
    start.step = 0;//一定要初始化
    q.push(start);
    while(!q.empty()){
        start = q.front();
        q.pop();
        if(start.x == e_x && start.y == e_y && start.z == e_z){
            flag = start.step;
            return ;
        }
        //上下左右前后地走,拓展子节点
        for(int i = 0;i < 6;i++){
            node child;
            child.x = start.x + mv[i][0];
            child.y = start.y + mv[i][1];
            child.z = start.z + mv[i][2];
            //如果越界
            if(child.x <= 0 || child.x > l || child.y <= 0 || child.y > r || child.z <= 0 || child.z > c){
                continue;
            }
            //如果是墙壁
            if(mp[child.x][child.y][child.z] == '#') continue;
            //如果已经走过了
            if(vis[child.x][child.y][child.z]) continue;
            child.step = start.step + 1;
            vis[child.x][child.y][child.z] = 1;
            q.push(child);
        }
    }
}
int main(){

    while(cin >> l >> r >> c){
        if(l == 0 && r == 0 && c == 0) break;
        memset(vis,0,sizeof(vis));
        flag = 0;
        for(int i = 1;i <= l;i++){
            for(int j = 1;j <= r;j++){
                for(int k = 1;k <= c;k++){
                    cin >> mp[i][j][k];
                    if(mp[i][j][k] == 'S'){
                        s_x = i,s_y = j,s_z = k;
                    }
                    if(mp[i][j][k] == 'E'){
                        e_x = i,e_y = j,e_z = k;
                    }
                }
            }
        }
        bfs(s_x,s_y,s_z);
        if(flag){
            cout << "Escaped in " << flag << " minute(s)." << "\n";
        }else{
            cout << "Trapped!" << "\n";
        }
    }
    
} 